<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /*
        [[getter]]   [[setter]]
        访问器属性
            Configurable: 属性是否可配置,能否被删除
            Enumerable: 属性是否可被遍历
            set: 写入属性值时调用的函数，默认接受一个参数：设置的值
            get: 读取属性时调用的函数，返回值是读取的值
        */
        var obj = {
            lastName: '李',
            firstName: '白',
            // 获取全名
            get fullName () {
                console.log('获取全名');
                return this.lastName + this.firstName
            },
            // 设置全名
            set fullName (v) {
                this.lastName = v[0];
                this.firstName = v.slice(1);
            }
        }

        // console.log(obj.fullName.get());
        // obj.fullName = '张三';
        // console.log(obj);

        var obj1 = {
            lastName: "李",
            firstName: "太白",
        }

        Object.defineProperties(obj1, {
            fullName: {
                configurable: true,
                enumerable: true,
                get () {
                    console.log('获取全名');
                    return this.lastName + this.firstName
                },
                set (v) {
                    this.lastName = v[0];
                    this.firstName = v.slice(1);
                }
            }
        })
        console.log(obj1.fullName);
        obj1.fullName = '李四';
        console.log(obj1);
    </script>
</body>
</html>